class MyBitmap {
  constructor(size) {
    this.words = [];
    this.size = size;
  }
  /**
   * 判断bitmap某一位的状态
   * @param {*} bitIndex  位图的第bitIndex位
   */
  getBit (bitIndex) {
    if (bitIndex < 0 || bitIndex > this.size - 1) {
      throw Error('超出bitmap有效范围')
    }
    let wordIndex = this.getWordIndex(bitIndex);
    return (this.words[wordIndex] & (1 << bitIndex)) != 0
  }
  /**
    * 把bitmap某一位设为真
    * @param bitIndex  位图的第bitIndex位
    */
  setBit (bitIndex) {
    if (bitIndex < 0 || bitIndex > this.size - 1) {
      throw Error("超出bitmap有效范围")
    }
    let wordIndex = this.getWordIndex(bitIndex);
    this.words[wordIndex] |= (1 << bitIndex);
  }

  /**
     * 定位bitmap某一位所对应的word
     * @param bitIndex  位图的第bitIndex位
     */
  getWordIndex (bitIndex) {
    //右移6位，相当于除以64
    return bitIndex >> 6;
  }
}

let bitMap = new MyBitmap(128);
bitMap.setBit(126);
bitMap.setBit(75);
console.log(bitMap.getBit(126));
console.log(bitMap.getBit(78));